package example.discard;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

public class DiscardServerHandler extends SimpleChannelInboundHandler<Object> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
		// drop msg
		 if(msg instanceof ByteBuf){
			 ByteBuf bf = (ByteBuf)msg;
			System.out.println("direct" + bf.isDirect());
			System.out.println( "msg : "+ bf.toString(CharsetUtil.UTF_8));
		 }
	}
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		// TODO Auto-generated method stub
		cause.printStackTrace();
		ctx.close() ;
	}

}
